#include <stdio.h>
#include <string>
#include <iostream>
#include <sstream>
using namespace std;


int main(int argc, char** argv[])
{
	int foundTreasure = 0;
	int lives = 3;
	
		int looper;
		int X;
		int Y;
		int treasure1[2];
		int treasure2[2];
		int treasure3[2];



		// if treasure is found put a X on the - 
		// if treasure is not found put a N and take a life off( has 3 lives ) 




		cout << "Player 1 place treasures now:" << endl;

		for (looper = 0; looper < 3; looper++)
		{
			cout << "X:";
			string input = "";
			stringstream stream;
			getline(cin, input);
			stream.str(input);
			stream >> X;
			stream.clear();

			cout << "Y:";
			getline(cin, input);
			stream.str(input);
			stream >> Y;
			stream.clear();

			cout << endl;

			if (X >= 8 || Y >= 8)
			{
				cout << "Please type in a number between 0 and 8 for both the X Axis and The Y Axis" << endl << endl;
				looper = looper - 1;

			}

			if (looper == 0 && X > 0 && X < 8 && Y > 0 && Y < 8)
			{
				treasure1[0] = X;
				treasure1[1] = Y;// 1st treasure location
			}
			else if (looper == 1 && X > 0 && X < 8 && Y > 0 && Y < 8)
			{
				treasure2[0] = X;
				treasure2[1] = Y;// 2nd treasure location
			}
			else if (looper==2 && X > 0 && X < 8 && Y > 0 && Y < 8)
			{
				treasure3[0] = X;
				treasure3[1] = Y;// 3rd treasure location
			}


			cout << "Treasure " << looper + 1 << " placed" << endl;



		}

		cout << endl;
		int looper2 = 0;
		int x2;
		int y2;
		int Player2Guess[2];
		string map[9][9] = {
			{" ","0","1","2","3","4","5","6","7"},
			{"0","-","-","-","-","-","-","-","-"},
			{"1","-","-","-","-","-","-","-","-"},
			{"2","-","-","-","-","-","-","-","-"},
			{"3","-","-","-","-","-","-","-","-"},
			{"4","-","-","-","-","-","-","-","-"},
			{"5","-","-","-","-","-","-","-","-"},
			{"6","-","-","-","-","-","-","-","-"},
			{"7","-","-","-","-","-","-","-","-"},
		};

		// X on a - is where player 2 has found a treasure 
		// and an N on a - is where player 2 has not found a treasure and has lost a life 

		for (int y = 0; y < 9; y++) {
			for (int x = 0; x < 9; x++) {
				cout << map[y][x] << "  ";
			}
			cout << endl;
		}


		while (lives > 0 && foundTreasure < 3)
		{
			cout << "Player 2 Guess" << endl;

			cout << "X:";
			string input = "";
			stringstream stream;
			getline(cin, input);
			stream.str(input);
			stream >> x2;
			stream.clear();

			cout << "Y:";
			getline(cin, input);
			stream.str(input);
			stream >> y2;
			stream.clear();
			cout << endl;

			Player2Guess[0] = x2;
			Player2Guess[1] = y2;

			int P2GuessX = Player2Guess[0] + 1;
			int P2GuessY = Player2Guess[1] + 1;

			if (Player2Guess[0] == treasure1[0] && Player2Guess[1] == treasure1[1] || Player2Guess[0] == treasure2[0] && Player2Guess[1] == treasure2[1] || Player2Guess[0] == treasure3[0] && Player2Guess[1] == treasure3[1])
			{
				map[P2GuessX][P2GuessY] = "X";

				foundTreasure = foundTreasure + 1;

				cout << "You found " << foundTreasure << " Treasures" << endl;

				for (int y = 0; y < 9; y++)
				{
					for (int x = 0; x < 9; x++)
					{
						cout << map[y][x] << "  ";
					}
					cout << endl;
				}
			}
			else
			{
				lives = lives - 1;

				cout << "No Treasure here, You have " << lives << "  lives left" << endl;

				map[P2GuessX][P2GuessY] = "N";

				for (int y = 0; y < 9; y++)
				{
					for (int x = 0; x < 9; x++)
					{
						cout << map[y][x] << "  ";
					}
					cout << endl;
				}
			}
		}
		
		if (lives == 0 )
		{
			cout << "Player 2 you have " << lives << " lives and found " << foundTreasure << " out of 3 treasures. Player 1 Wins" << endl;
		}

		if (foundTreasure == 3)
		{
			cout << "Player 2 you found all 3 treasures.Player 2 wins" << endl;
		}

	//pause
	cin.get();
	return 0;
}